package model.service;

import org.json.JSONObject;

import android.util.Log;
import model.Machine;
import model.service.ServiceBehaviour;

@SuppressWarnings("unused")
public class JsonBehaviour extends ServiceBehaviour
{
	/*
	 * this method translates the assumed JSON in the string that is given into a Machine object and returns this. 
	 */
	@Override
	public Machine translateResponseToMachine(String response) throws Exception
	{					
		JSONObject jsonMachine = new JSONObject(response);			
		JSONObject jsonOrder = jsonMachine.getJSONObject("Order");
				
		return createMachine(jsonMachine.getString("ID"), jsonMachine.getString("Name"), 
					createOrder(
						jsonOrder.getString("DBID"), jsonOrder.getString("ID"), jsonOrder.getLong("Duration"), jsonOrder.getString("StartDateTimeString"),  
						jsonOrder.getString("EndDateTimeString"), jsonOrder.getString("RequestedStartDateTimeString"),  jsonOrder.getString("RequestedEndDateTimeString"),  
						jsonOrder.getString("RequestedProduct"), jsonOrder.getString("RequestedProductDescription"),  jsonOrder.getString("ActualProduct"),  
						jsonOrder.getString("ActualProductDescription"), jsonOrder.getInt("RequestedCount"),  jsonOrder.getInt("ActualCount")
					),
				jsonMachine.getString("Description"), jsonMachine.getDouble("CurrentSpeed"), jsonMachine.getString("CurrentStatus"));		
	}

}